package cc.mrbird.prisoner.service.impl;

import cc.mrbird.common.base64.Base;
import cc.mrbird.common.domain.QueryRequest;
import cc.mrbird.common.service.impl.BaseService;

import cc.mrbird.prisoner.dao.VideoMapper;
import cc.mrbird.prisoner.domain.JzVideo;

import cc.mrbird.prisoner.service.VideoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("videoService")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class VideoServiceImpl  extends BaseService<JzVideo> implements VideoService {

    @Autowired
    private VideoMapper video;

    @Override
    public List<JzVideo> findVideo(JzVideo jzVideo, QueryRequest request) {
        List<JzVideo> result = video.findVideo(jzVideo);
        String photo = null;
        String video = null;
        String text = null;
      System.out.println("进入到方法findvideo");
        if (result.size() > 0) {
            System.out.println("进入if中");
            for (int i = 0; i < result.size(); i++) {
                System.out.println("进入到循环中");

                if (StringUtils.isNotBlank(result.get(i).getPhotoUrl())) {
                    System.out.println(result.get(i).getPhotoUrl());
                    photo = result.get(i).getPhotoUrl();
                    String a[] = photo.split("//");
                    photo = "http://61.181.104.62:8081/" + a[1];
                    result.get(i).setPhotoUrl(photo);
                    System.out.println(result.get(i).getPhotoUrl());
                }
                if (StringUtils.isNotBlank(result.get(i).getVideoUrl())) {
                    System.out.println(result.get(i).getVideoUrl());
                    video = result.get(i).getVideoUrl();
                    String a[] = video.split("//");
                    video = "http://61.181.104.62:8081/" + a[1];
                    result.get(i).setVideoUrl(video);
                    System.out.println(result.get(i).getVideoUrl());
                }
              //拼接texturl路径信息
             if(StringUtils.isNotBlank(result.get(i).getTextUrl())){
                    System.out.println(result.get(i).getTextUrl());
                    text=result.get(i).getTextUrl();
                    String a[]=text.split("//");
                    text="http://61.181.104.62:8081/"+a[1];
                    result.get(i).setTextUrl(text);
                    System.out.println(result.get(i).getTextUrl());
                }

            }
        }

        return result;
    }

    @Override
    public List<JzVideo> findSingleVideo(JzVideo jzVideo) {
        List<JzVideo> result = video.findVideo(jzVideo);
        String photo = null;
        String video = null;
/*        String text=null;*/
      /*  System.out.println("进入到了查询方法");*/
        if (result.size() > 0) {
            System.out.println("进入到了if方法");
           /* for (int i = 0; i < result.size(); i++) {*/
                System.out.println("进入到了循环方法");
                if (StringUtils.isNotBlank(result.get(0).getPhotoUrl())) {
                    photo = result.get(0).getPhotoUrl();
                    String act = Base.imageToBase64Str(photo);
                    result.get(0).setPhotoUrl(act);
                }

                if (StringUtils.isNotBlank(result.get(0).getVideoUrl())) {
                    video = result.get(0).getVideoUrl();
                    String a[] = video.split("//");
                    video = "http://61.181.104.62:8081/" + a[1];
                    result.get(0).setPhotoUrl(video);
                }
               /* if (StringUtils.isNotBlank(result.get(i).getTextUrl())) {
                    text = result.get(i).getTextUrl();
                    String a[] = text.split("//");
                    text = "http://61.181.104.62:8081/" + a[1];
                    result.get(i).setTextUrl(text);
                }*/


        }
            return result;
        }



}